///*
//package com.example.fzj.hazelcastshiro.shiro;
//
//*/
///**
// * @Author fanzj
// * @Date 2021/8/15 3:36 下午
// * @Version 3.0
// * @Description
// */
//
//import javax.annotation.Resource;
//
//import com.hazelcast.map.IMap;
//import org.apache.shiro.ShiroException;
//import org.apache.shiro.cache.Cache;
//import org.apache.shiro.cache.CacheException;
//import org.apache.shiro.cache.CacheManager;
//import org.apache.shiro.cache.MapCache;
//import org.apache.shiro.util.Destroyable;
//import org.apache.shiro.util.Initializable;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//
//import com.hazelcast.config.Config;
//import com.hazelcast.core.Hazelcast;
//import com.hazelcast.core.HazelcastInstance;
//import com.hazelcast.spring.cache.HazelcastCacheManager;
//
//public class SpringCacheManagerWrapper implements  CacheManager, Initializable, Destroyable {
//
//    public static final Logger log = LoggerFactory.getLogger(SpringCacheManagerWrapper.class);
//    @Resource
//    private HazelcastCacheManager cacheManager;
//
//    private boolean implicitlyCreated = false;
//
//    private HazelcastInstance hazelcastInstance;
//
//    private Config config;
//
//    public <K, V> Cache<K, V> getCache(String name) throws CacheException {
//        //returned map is a ConcurrentMap
//        IMap<K, V> map = hazelcastInstance.getMap(name);
//        return new MapCache<K, V>(name, map);
//    }
//
//    protected HazelcastInstance ensureHazelcastInstance() {
//        if (this.hazelcastInstance == null) {
//            this.hazelcastInstance = createHazelcastInstance();
//            this.implicitlyCreated = true;
//        }
//        return this.hazelcastInstance;
//    }
//
//    public void init() throws ShiroException {
//        if (this.cacheManager == null) {
//            ensureHazelcastInstance();
//        } else {
//            hazelcastInstance = cacheManager.getHazelcastInstance();
//        }
//    }
//
//    protected HazelcastInstance createHazelcastInstance() {
//        return Hazelcast.newHazelcastInstance(this.config);
//    }
//
//    protected final boolean isImplicitlyCreated() {
//        return this.implicitlyCreated;
//    }
//
//    public void destroy() throws Exception {
//        if (this.implicitlyCreated) {
//            try {
//                this.hazelcastInstance.getLifecycleService().shutdown();
//            } catch (Throwable t) {
//                if (log.isWarnEnabled()) {
//                    log.warn("Unable to cleanly shutdown implicitly created HazelcastInstance.  " +
//                            "Ignoring (shutting down)...", t);
//                }
//            } finally {
//                this.hazelcastInstance = null;
//                this.implicitlyCreated = false;
//            }
//        }
//    }
//
//    public HazelcastInstance getHazelcastInstance() {
//        return hazelcastInstance;
//    }
//
//    public void setHazelcastInstance(HazelcastInstance hazelcastInstance) {
//        this.hazelcastInstance = hazelcastInstance;
//    }
//
//    public Config getConfig() {
//        return config;
//    }
//
//    public void setConfig(Config config) {
//        this.config = config;
//    }
//}
